/**
 * Created by Administrator on 15-7-27.
 */
var Stage = null,
	mStage = require("./stage.js");
var Drag = null,
	mDrag = require("./drag.js");
var ColHead = null,
	mColHead = require("./colHead.js");
var RowHead = null,
	mRowHead = require("./rowHead.js");
var mDragToSelect = require("./dragToSelect.js");
var DragToSelect = new mDragToSelect({container:$("#seatUlWrap")});
var Main = RichBase.extend({
	EVENTS : {
		"click" : {
			"#creatSeatBtn" : "onCreatSeatBtnClick"
		}
	},
	init : function(){
		Stage = new mStage({container:$("#seatUlWrap")});
		Drag = new mDrag({container:$("#seatUlWrap")});
		ColHead = new mColHead({container:$("#colHead")});
		RowHead = new mRowHead({container:$("#rowHead")});
		Drag.on("mousedown",function(data){
			DragToSelect.onMouseDown(data);
		})
		Drag.on("mousemove",function(data){
			var isDrag = data.isDrag;
			var x = data.x;
			var y = data.y;
			DragToSelect.onMouseMove(data);
			if(!isDrag) return false;
			ColHead.scroll(x);
			RowHead.scroll(y);
		})
		Drag.on("mouseup",function(data){
			DragToSelect.onMouseUp(data)
		})
	},
	onCreatSeatBtnClick : function(that,e){
		that.refresh();
	},
	getRowCount : function(){
		var val = $("#rowInp").val() || 0;
		return Number(val);
	},
	getColCount : function(){
		var val = $("#colInp").val() || 0;
		return Number(val);
	},
	getLayoutVal : function(){
		return $("#topFormGroup").find("input:radio:checked").attr("data-layout");
	},
	refresh : function(){
		var row = this.getRowCount();
		var col = this.getColCount();
		var layout = this.getLayoutVal();
		Stage.render({row:row,col:col,layout:layout});
		ColHead.render({col:col,layout:layout});
		RowHead.render({row:row});
		Drag.refresh({container:$("#seatUlWrap")});
	}
});

new Main();